package com.yj.core.config;


import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.boot.web.embedded.undertow.UndertowReactiveWebServerFactory;
import org.springframework.boot.web.embedded.undertow.UndertowServletWebServerFactory;
import org.springframework.context.annotation.Bean;

/**
 * 
 *
 * @author 杨旭平
 * @date 19-6-24
 */
@Slf4j
/*@Configuration*/
public class HttpConfiguration {

    @Value("${system.http.open:false}")
    private Boolean openHttp;

    @Value("${system.http.port:-1}")
    private Integer httpPort;

    /**
     * 配置内置的servlet容器工厂为tomcat.
     *
     * @return
     */
    /*@Bean
    public UndertowReactiveWebServerFactory undertowReactiveWebServerFactory() {

        if (openHttp && httpPort > 0) {
            log.info("启用http端口");
            UndertowReactiveWebServerFactory undertow = new UndertowReactiveWebServerFactory();
            undertow.addBuilderCustomizers((Undertow.Builder builder) -> {
                builder.addHttpListener(httpPort, "0.0.0.0");
            });
            return undertow;
        } else {
            return new UndertowReactiveWebServerFactory();
        }
    }

    @Bean
    public UndertowServletWebServerFactory undertowServletWebServerFactory() {

        if (openHttp && httpPort > 0) {
            log.info("启用http端口");
            UndertowServletWebServerFactory undertow = new UndertowServletWebServerFactory();
            undertow.addBuilderCustomizers((Undertow.Builder builder) -> {
                builder.addHttpListener(httpPort, "0.0.0.0");
            });
            return undertow;
        } else {
            return new UndertowServletWebServerFactory();
        }
    }*/
}
